<?php
/** [广告控制器]
 * @Author: 976123967@qq.com
 * @Date:   2015-01-16 11:33:22
 * @Last Modified by:   Administrator
 * @Last Modified time: 2015-01-17 17:44:04
 */
class AdAction extends PublicAction{


	public $logic;

	public $postPsid;

	public $getPsid;


	/**
	 * [_initialize 初始化]
	 * @return [type] [description]
	 */
	public function _initialize()
	{
		parent::_initialize();

		$this->logic   		 = D('Ad','Logic');

		// 广告位置
		$this->assign('position',D('Position','Logic')->get_all());

		$this->postPsid = I('post.position_psid');
		$this->getPsid  = I('get.psid');
	}

	/**
	 * [index 所有广告]
	 * @return [type] [description]
	 */
	public function index()
	{

		$data = $this->logic->get_all();
		if($data)
		{
			$this->assign('page',$data['page']);
			unset($data['page']);
		}
		$this->assign('data',$data);
		

		$this->display();
	}

	/**
	 * [add 添加广告]
	 */
	public function  add()
	{

		if(IS_POST)
		{
		
			if(!$this->logic->add_ad())
				$this->error($this->logic->getError());
			$this->success('广告添加成功',U('Ad/index',array('psid'=>$this->postPsid)));
			die;
		}

		$this->display();
	}


	/**
	 * [edit 编辑]
	 * @return [type] [description]
	 */
	public function  edit()
	{


		if(IS_POST)
		{
		
			if(!$this->logic->update_ad())
				$this->error($this->logic->getError());
			$this->success('广告编辑成功',U('Ad/index',array('psid'=>$this->postPsid)));
			die;
		}

		$field = $this->logic->find_one();
		if(!$field)
			$this->error($this->logic->getError());
		$this->assign('field',$field);
		$this->display();
	}

	/**
	 * [del 删除]
	 * @return [type] [description]
	 */
	public function del()
	{
	
		if(!$this->logic->del_ad())
			$this->error($this->logic->getError());
		$this->success('广告删除成功',U('Ad/index',array('psid'=>$this->getPsid)));
	}


	/**
	 * [operation 执行批量处理操作]
	 * @return [type] [description]
	 */
	public function operation()
	{
		if(!$msg = $this->logic->operation())
			$this->error($this->logic->getError());
		$this->success($msg,U('Ad/index'));
	}

}